package com.mobor.moborsvr.infra.search.impl;

import java.util.concurrent.Callable;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.mobor.moborsvr.infra.dao.BaseWorker;

/**
 * Generic class to run different data access operations implements Java Callable interface.
 * Generally should be acquired from Spring context since it's created by {@link SearchWorkerFactory}
 * @author teroleg
 * @param <T> - return type
 * 
 */
public class SearchWorker<T> implements Callable<T>{
	
	private static final Logger logger = LogManager.getLogger(SearchWorker.class.getName());
		
	private BaseWorker baseDao;
	
	public SearchWorker(){
		
	}
	
	public SearchWorker(BaseWorker baseDao){
		this.baseDao = baseDao;
	}
  
	@SuppressWarnings("unchecked")	
	public T call() throws Exception {
		logger.debug("Running thread : " + Thread.currentThread().getId());
		
		return (T) baseDao.work();
	}

	public BaseWorker getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(BaseWorker baseDao) {
		this.baseDao = baseDao;
	}
}
